package com.zxhwolfe.androidCanvasTest;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.BitmapFactory;
import android.util.Log;

public class LoadImage {
	private String log = "loadImage";
    HttpURLConnection uc ;
    URL url;
    InputStream is;
    BufferedInputStream bis;
    private static final String ip="code.google.com/android/images/logo_android.gif";
    private static final String host="";
    private static final String path = "http://" + ip +host ;


    public  LoadImage(){
     
                openConn();
                sendRequest();
                getRespones();
                closeConn();
      
    }

    private void openConn(){
        try {
            url=new URL(path);
            uc = (HttpURLConnection)url.openConnection();
            uc.setDoInput(true);
        }catch (MalformedURLException e){
        	Log.d(log,"exception openConn(1)");
            e.printStackTrace();
        } catch (IOException e) {
        	Log.d(log,"exception openConn(2)");
            e.printStackTrace();
        }
    }

    private void sendRequest(){
        try {
            uc.connect();
        } catch (IOException e) {
        	Log.d(log,"exception sendRequest()");
             e.printStackTrace();
        }
    }

    private void getRespones(){
        try {
            is = uc.getInputStream();
            Log.d("lenght",""+uc.getContentLength());
            bis = new BufferedInputStream(is);
            Config.loadimage = BitmapFactory.decodeStream(bis);
        } catch (IOException e1) {
        	Log.d(log,"exception getRespones()");
            e1.printStackTrace();
        }
    }

    private void closeConn(){
        try {
            uc.disconnect();
            bis.close();
            is.close();
        } catch (IOException e) {
        	Log.d(log,"exception closeConn()");
            e.printStackTrace();
        }
    }
}
